<?php
/**
 * Created by PhpStorm.
 * User: majiawen
 * Date: 2018/1/19
 * Time: 下午12:18
 */

namespace app\admin\controller\v1;

use app\admin\controller\Fun;
use app\common\Model\User;
use app\common\Server\AdminCaptcha;
use app\common\Server\Validate;

/**
 * @title 后台登录类V1
 * @description 接口说明
 *
 * @header name:copyright require:1 default:v1 desc:版本号(全局)
 */
class Login extends Base
{
    /**
     * @title 发送验证码
     * @description
     * @author majiawen
     * @url /admin/index/index
     * @method POST
     *
     * @header name:interface require:1 default:Login desc:接口组(全局)
     *
     * @param name:command type:string require:1 default: other:sendCaptcha desc:发送验证码
     * @param name:mobile type:string require:1 default: other:18900000000 desc:手机号
     *
     * @return data:[]
     */
    public function sendCaptcha()
    {
        $mobile = $this->param['mobile'];

        $mobile = Validate::instance()->getPhone($mobile);
        if (!$mobile) {
            return Fun::error('801004');
        }

        //发送验证码
        $rtn = AdminCaptcha::instance()->send($mobile);
        if ($rtn === true) {
            return Fun::success([], '发送成功');
        } elseif ($rtn === 2) {
            return Fun::error('801002');
        } elseif ($rtn === 3) {
            return Fun::error('801003');
        } else {
            return Fun::error('999992');
        }
    }
    /**
     * @title 判断验证码
     * @description
     * @author majiawen
     * @url /admin/index/index
     * @method POST
     *
     * @header name:interface require:1 default:Login desc:接口组(全局)
     *
     * @param name:command type:string require:1 default: other:Login desc:发送验证码
     * @param name:mobile type:string require:1 default: other:18900000000 desc:手机号
     * @param name:captcha type:string require:1 default: other:18900000000 desc:验证码
     *
     * @return data:[]
     */
    public function Login(){
        $captcha = $this->param['captcha'];
        $mobile = $this->param['mobile'];
        if(!AdminCaptcha::instance()->verify($mobile,$captcha))
        {
            return Fun::error('801000');
        }
        return Fun::success('判断权限的数组（暂无）');
    }
}